<?

/********************************************
* eventlist.php
*
* This page displays all available events for the user to choose
*
********************************************/

//include files
include "config.php";
include "../lib/db.php";
include "../lib/tbatv_lib.php";

$relpath = "";
$tba = new tbatvController();

$year = sanatizeGet($_GET['year']);
if (is_null($year) OR !is_numeric($year)) $year = date('Y');

$title = $year . " Events";

include "header.php";
?>

<h1><? echo $year ?> FIRST FRC Events</h1>

<?
//look up other years in the TBA system
$all_years = array();
foreach ($tba->getAllYears($year) as $old_year) {
    $all_years[] = "<a href=\"?year={$old_year}\">{$old_year}</a>";
}
$other_years_string = "<p><strong>Other Years: </strong>" . join(", ", $all_years) . "</p>\r\n";
print $other_years_string;

?>

<p>If you have video from a competition not listed here that you would be willing to let us host, let us know! E-mail us at <a href="mailto:contact@thebluealliance.net">contact@thebluealliance.net</a>.</p>

<?
//Output this week's events.
if ($year == date('Y')) {
	$week = $tba->getCurrentWeek();
	$list_of_events = $tba->getEventsByWeek($week);
	if (count($list_of_events) > 0) {
	    printf("<table class=\"table_alt\">\r");
		printf('<tr class="table_toprow" id="week%s"><td colspan="5">%s This Week: %s %s</td></tr>', 
		    $week, $weekimages[$week], $weeknames[$week], $weekimages[$week]);
		printf('<tr class="table_toprow"><td>Teams</td><td>Videos</td><td>Name</td><td>Location</td><td>Site</td></tr>');
		$zebra = 0;
		foreach ($list_of_events as $event) {
			printf("<tr class=\"table_row%s\">", ($zebra & 1));
			$zebra++;
			
			//decide on website
			if ($event->getWebsite() != '') {
				$website = "<a href=\"{$event->getWebsite()}\" title=\"{$event->getName()}\" target=\"_blank\"><img src=\"images/globe.png\"></a>";
			} else {
				$website = '';
			}
									
			//spit it out
			printf("<td><strong>%s</strong></td><td><strong>%s</strong></td><td><strong>%s</strong></td><td>%s</td><td>%s</td></tr>\r",
				$event->getTeamCount(), $event->getVideoCount(), $event->linkto($event->getName()), $event->getLocation(), $website);
		}
		printf("</table>");
	}
}
?>


<h1>Select a <?echo $year ?> Event</h1>
<?

printf("<table class=\"table_alt\">\r");		
foreach ($all_weeks as $week) {
	$list_of_events = $tba->getEventsByWeek($week, $year);
	if (count($list_of_events) > 0) {
		printf('<tr class="table_toprow" id="week%s"><td colspan="5">%s %s %s</td></tr>', 
		    $week, $weekimages[$week], $weeknames[$week], $weekimages[$week]);
		printf('<tr class="table_toprow"><td>Teams</td><td>Videos</td><td>Name</td><td>Location</td><td>Site</td></tr>');
		
		$zebra = 0;
		foreach ($list_of_events as $event) {
		    printf("<tr class=\"table_row%s\">", ($zebra & 1));
			$zebra++;
			
			//decide on website
			if ($event->getWebsite() != '') {
				$website = "<a href=\"{$event->getWebsite()}\" title=\"{$event->getName()}\" target=\"_blank\"><img src=\"images/globe.png\"></a>";
			} else {
				$website = '';
			}
									
			//spit it out
			printf("<td><strong>%s</strong></td><td><strong>%s</strong></td><td><strong>%s</strong></td><td>%s</td><td>%s</td></tr>\r",
				$event->getTeamCount(), $event->getVideoCount(), $event->linkto($event->getName()), $event->getLocation(), $website);
		}
	}
}
printf("</table>");

include "footer.php";
?>